Skip to content

4. 使用taiwindcss

安装依赖

js
pnpm install -D tailwindcss postcss autoprefixer
pnpm install -D tailwindcss postcss autoprefixer

执行init命令

r
npx tailwindcss init -p
npx tailwindcss init -p

会生成tailwind.config.js 和postcss.config.js文件

修改配置

修改tailwind.config.js:

js
/** @type {import('tailwindcss').Config} */  
module.exports = {  
  darkMode: 'class',  
  content: [  
    './docs/**/*.{html,js,vue,ts,md}',  
    './docs/.vitepress/**/*.{html,js,vue,ts,md}',  
  ],  
  theme: {  
    extend: {},  
  },  
  plugins: [],  
}
/** @type {import('tailwindcss').Config} */  
module.exports = {  
  darkMode: 'class',  
  content: [  
    './docs/**/*.{html,js,vue,ts,md}',  
    './docs/.vitepress/**/*.{html,js,vue,ts,md}',  
  ],  
  theme: {  
    extend: {},  
  },  
  plugins: [],  
}

引入css

主题文件 .vitepress/theme/style.css

css
@tailwind base; 
@tailwind components;
@tailwind utilities;
@tailwind base; 
@tailwind components;
@tailwind utilities;

相关参考

Install Tailwind CSS with Vite - Tailwind CSS